class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        min_price = max(prices)
        max_profit = 0
        for p in prices:
            if p < min_price:
                min_price = p
            elif p - min_price > max_profit:
                max_profit = p - min_price
        return max_profit


solution = Solution()
# r = solution.maxProfit([7,1,5,3,6,4])
r = solution.maxProfit([2,5,1,3])
# r = solution.maxProfit([7,6,4,3,1])
print(r)
